import re
# *匹配前一个字符0次或者无限次(可以没有)
# st = "hello world\nhello python"
# m1 = re.match(".*",st)
# print(m1.group())  # hello world
# st2 = "Hello World\nhello python"
# m2 = re.match("[A-Z][a-z]*",st2)
# print(m2.group())
# st3 = "hello"
# m3 = re.match("[A-Z]*[a-z]",st3)  # 大写字母可以没有也可以有很多个
# print(m3.group())

# +匹配前一个字符1次或者无限次(必须要有一个)
# st = "hello world\nhello python"
# m1 = re.match(".+",st)
# print(m1.group())  # hello world
# st2 = "Hello World\nhello python"
# m2 = re.match("[A-Z][a-z]+",st2)
# print(m2.group())
# st3 = "hello"
# m3 = re.match("[A-Z]+[a-z]",st3)  # 至少要保证有一个大写字母也可以有很多个
# print(m3.group())

# ?匹配前一个字符0次或者1次(有且只有一个可以没有)
# m1 = re.match("[1-9]?[0-9]","2022")  # ?匹配到了一次
# print(m1.group())
# m2 = re.match("[3-9]?[0-9]","2022")  # 2-[0-9]
# print(m2.group())

# {m}匹配前一个字符m次(多了也不行少了也不行)
st = "23fg67890"
# m1 = re.match("[a-z0-9]{6}",st)
# print(m1.group())
# m1 = re.match("[a-z0-9]{5}","hel2")
# print(m1.group())

# {m,n}匹配前一个字符至少m次最多n次(在这个区间范围内多了就按照原本的内容来)
m1 = re.match("[a-z0-9]{2,6}",st)  # 匹配最多的
print(m1.group())
m2 = re.match("[a-z0-9]{2,11}",st)  # 超出就按照原本内容
print(m2.group())
m3 = re.match("[a-z0-9]{2,11}","hrughd6")
print(m3.group())  # 报错